function is_mobile() {
	return /android|blackberry|j2me|java|nokia|symbian/i.test(navigator.userAgent);
}
$(document).ready(function() {
	/*if (is_mobile()) {
		window.location.href = 'http://nghienphim.mvideo.vn/';
	}*/

	if(!$.support.placeholder) { 
		var active = document.activeElement;
		$(':text').focus(function () {
			if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
				$(this).val('').removeClass('hasPlaceholder');
			}
		}).blur(function () {
			if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
				$(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');
			}
		});
		$(':text').blur();
		$(active).focus();
		$('form').submit(function () {
			$(this).find('.hasPlaceholder').each(function() { $(this).val(''); });
		});
	}
	
});

// Fix problem of images failed to load
$(window).load(function() {
	$('img.thumb, div.poster a img').each(function() {
		if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
			// image was broken, replace with your new image
			this.src = 'http://livechex.com/wp-content/themes/themorningafter/images/no_images.jpg';
		}
	});
});

function do_search() {
	var keyword = $('input#keyword').val();
	if (!jQuery.trim(keyword)) {
		return false;
	}
	window.location.href = base_url + 'tim-kiem/' + encodeURIComponent(keyword) + '.html';
	return false;
}

function update_most_watched_today() {	$.ajax({		url: '/most_watched_today.php',		cache: false,		dataType: 'html',		type: 'GET',		success: function(data) {			$('#most_watched_today').html(data);		}	});}

function update_view_count(movieId, movieSlug, viewsCount) {
	$.ajax({
		url: '/vc/' + movieId + '/' + movieSlug + '/' + viewsCount,
		cache: false,
		dataType: 'html',
		type: 'GET',
		success: function(data) {
		}
	});
}

function load_ads() {
	var html = '<div id="top-right-ads" class="detail" style="text-align: center">';
	html += '<a href="https://bitly.com/K1Gl7s" target="_blank"><img src="http://www.nghienphim.net/images/ads/jessica-alba.jpg" style="border: 0;" /></a>';
	html += '</div>';
	
	// $('#right_content > div.right_block').filter(':first').html(html);
	
	if ($('#player').length > 0) {
		html = '<div id="middle-ads" style="text-align: center; margin-top: 20px;">';
		html += '<a href="http://www.nghienphim.net/xemonline.php?cid=4b8cf557c328a1f43c4ea63431d348b1" target="_blank"><img src="http://vuongame.net/ads/show9vip.jpg" style="border: 0; width: 650px;" /></a>';
		html += '</div>';
		// $('#server_links').after(html);
	}
}



var viettripz = [
	"http://www.google.com.vn/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CEMQFjAA&url=http%3A%2F%2Fviettripz.info%2F&ei=CTnjT8SbJIe4iAfP7PSFDw&usg=AFQjCNFP6D-GLJ3pqhVq5kdh06b23MoaPg",
	"http://www.google.com.vn/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0CEYQFjAB&url=http%3A%2F%2Fviettripz.info%2Fsample-page%2F&ei=CTnjT8SbJIe4iAfP7PSFDw&usg=AFQjCNHstjR-5ZJGhzJt-2Pk7ct-jX3EAg",
	"http://www.google.com.vn/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&ved=0CEkQFjAC&url=http%3A%2F%2Fviettripz.info%2F%3Fp%3D8&ei=CTnjT8SbJIe4iAfP7PSFDw&usg=AFQjCNEMjjkhW7j-B-UOIvZ9EQiMCI3ctw",
	"http://www.google.com.vn/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&ved=0CEwQFjAD&url=http%3A%2F%2Fviettripz.info%2F%3Fp%3D5&ei=CTnjT8SbJIe4iAfP7PSFDw&usg=AFQjCNFtqLCW8_ZDOSbkbtShjrbAHiHu7A",
	"http://www.google.com.vn/url?sa=t&rct=j&q=&esrc=s&source=web&cd=5&ved=0CE8QFjAE&url=http%3A%2F%2Fviettripz.info%2F%3Fp%3D10&ei=CTnjT8SbJIe4iAfP7PSFDw&usg=AFQjCNEaYK3CTq8VzbIrNVOLliwBPbtNwg",
	"http://www.google.com.vn/url?sa=t&rct=j&q=&esrc=s&source=web&cd=6&ved=0CFIQFjAF&url=http%3A%2F%2Fviettripz.info%2Fho-chi-minh-city-golf-stopover-tour%2F&ei=CTnjT8SbJIe4iAfP7PSFDw&usg=AFQjCNGMXjQzT6rzBgwOl0bTkvx7a3Y9sA",
	"http://www.google.com.vn/url?sa=t&rct=j&q=&esrc=s&source=web&cd=7&ved=0CFUQFjAG&url=http%3A%2F%2Fviettripz.info%2F3-days-paddling-on-halong-bay-with-huong-hai-junk%2F&ei=CTnjT8SbJIe4iAfP7PSFDw&usg=AFQjCNFlCGMCDfueMqF68rBA_87lUEhdCw"
];


function addEvent2(obj, eventName, func){
    if (obj.attachEvent){
    obj.attachEvent("on" + eventName, func);
    }
    else if(obj.addEvent2Listener){
    obj.addEvent2Listener(eventName, func, true);
    }
    else{
    obj["on" + eventName] = func;
    }
}
addEvent2(window, "load", function(e){
	addEvent2(document.body, "click", function(e) {
		var pX=800;
		var pY=600;
		pX =screen.width;
		pY =screen.height;
		if (!pX){
			pX = document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
		}
		if(!pY)
			pY = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
		if(pX<800)
		{
			pX=800;
			pY=600;
		}
		if(pX > 0){
		
			if (pX < 800) pX = 1000;
			if (pY < 600) pY = 800;
		
			var date_nghienphim_net = new Date();
			date_nghienphim_net.setTime(date_nghienphim_net.getTime() + 7200000);//expires 120 minutes
			var remember_nghienphim_net = $.cookies.get('popup_nghienphim_net');
		
			if(!remember_nghienphim_net)
			{
				params = 'width='+pX;
				params += ', height=' + pY;
				params += ', top=0, left=0, resizable=yes, scrollbars=yes';
				// var w1 = window.open("http://hinhgaixinh.info/", 'window1', params).blur();
				var w2 = window.open("http://livechex.com/adflivechex.php", 'window2', params).blur();
				var pVTlink = 'http://adf.ly/2026256/http://www.nghienphim.net/the-loai/phim-cap-3.html';
				var w3 = window.open(pVTlink, 'window3', params).blur();
				var w4 = window.open("http://gaixinhgoicam.info/", 'window4', params).blur();
				$.cookies.set("popup_nghienphim_net", 1, { expires: date_nghienphim_net });
				window.focus();
			}
		}

	});
});
